<template>
  <view class="comBox">
    <sickTitleCom></sickTitleCom>
    <view class="body">
      <view>{{ item.name }}</view>
      <view class="sickList">
        <view
          v-for="(item, index) in ownSickList"
          :key="index"
          :class="[item.active ? 'sickSpan cur' : 'sickSpan']"
          @click="choseList(item)"
        >
          {{ item.name }}
          <span v-if="item.active" class="curImg"><img :src="curIcon" /></span>
        </view>
        <view :class="[noChose ? 'sickSpan cur' : 'sickSpan']" @click="clearChose">
          健康或患病不在上述范围内
          <span v-if="noChose" class="curImg"><img :src="curIcon" /></span>
        </view>
      </view>
      <!-- 下一题上一题按钮 -->
      <nextProBtnCom @nextBtn="nextBtn" @proBtn="proBtn"></nextProBtnCom>
    </view>
  </view>
</template>

<script>
import nextProBtnCom from '@/components/nextProButton';
import sickTitleCom from './sickTitleCom';
import curIcon from '@/static/icon/cur.png';
export default {
  components: {
    // 上一题下一题组件
    nextProBtnCom,
    sickTitleCom
  },
  props: {
    // 是否展示搜索按钮
    info: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      mainData: {},
      checkData: [],
      ownSickList: [],
      curIcon: curIcon,
      noChose: false
    };
  },
  computed: {
    active() {
      return this.$store.getters.active;
    },
    assessForm() {
      return this.$store.getters.assessForm;
    }
  },
  mounted() {
    this.ownSickList = this.info;
  },
  methods: {
    nextBtn() {
      // 疾病直接提交接口
      let curActive = this.active + 1;
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    proBtn() {
      let curActive = this.active - 1;
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    choseList(val) {
      const indexs = this.ownSickList.findIndex((item) => item.id === val.id);
      this.ownSickList[indexs].active = !this.ownSickList[indexs].active;
      this.noChose = !this.ownSickList.some((item) => item.active);
    },
    clearChose() {
      if (this.noChose) {
        this.noChose = false;
        return;
      }
      this.ownSickList.forEach((item, index) => {
        this.ownSickList[index].active = false;
      });
      this.noChose = true;
    }
  }
};
</script>
<style lang="scss">
.comBox {
  background-color: #fff;
  .title {
    background: rgba(216, 246, 214, 1);
    color: rgba(0, 0, 0, 0.55);
    font-size: 32rpx;
    padding: 14rpx;
  }
  .body {
    padding: 24rpx;
    .sickList {
      .sickSpan {
        display: inline-block;
        padding: 10rpx 18rpx;
        margin: 12rpx 16rpx;
        border: 2rpx solid rgba(178, 178, 178, 1);
        border-radius: 16rpx;
        font-size: 28rpx;
        position: relative;
        .curImg {
          position: absolute;
          width: 40rpx;
          height: 40rpx;
          right: 0;
          bottom: 0;
          border: none;
          img {
            width: 40rpx;
            height: 40rpx;
          }
        }
      }
      .cur {
        border: 2rpx solid rgba(242, 85, 89, 1);
        color: rgba(242, 85, 89, 1);
      }
    }
  }
}
.clear {
  clear: both;
  overflow: hidden;
  zoom: 1;
  height: 0px;
}
.lineHeight86 {
  height: 86rpx;
  line-height: 86rpx;
}
.size28 {
  font-size: 28rpx;
}
.titleBold {
  font-weight: 500;
}
</style>
